package com.wanmait.recruitment.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.mapper.ProvinceMapper;
import com.wanmait.recruitment.pojo.Province;
import com.wanmait.recruitment.service.ProvinceService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class ProvinceServiceImpl implements ProvinceService {
    @Resource
    private ProvinceMapper provinceMapper;
    @Override
    public void insert(Province object) {
        provinceMapper.insertSelective(object);
    }

    @Override
    public void delete(Integer id) {
        provinceMapper.updateByPrimaryKey(id);
    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public void update(Province object) {
        provinceMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public Province findById(Integer id) {
        return provinceMapper.findById(id);
    }

    @Override
    @Cacheable("provinceCache")
    public List<Province> findAll() {
        return provinceMapper.finadAll();
    }

    @Override
    public List<Province> findAll(Province object) {
        return null;
    }

    @Override
    public PageInfo<Province> findPage(int pageNum, int pageSize) {
        return null;
    }

    @Override
    public PageInfo<Province> findListPage(Province province, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Province> provinces = provinceMapper.findListPage(province);
        PageInfo<Province> provincePageInfo = new PageInfo<>(provinces);
        return provincePageInfo;
    }
}
